home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 617 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. From: clamage@Eng (Steve Clamage)
  2. Message-ID: <4h784m$alj@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 1 Mar 1996 16:20:38 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 04 Mar 96 14:26:34 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Streams and eof()
  9. Organization: Sun Microsystems Inc.
  10. References: <4h5qp0$6di@engnews1.Eng.Sun.COM>
  11. Reply-To: clamage@Eng
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMTr9suEDnX0m9pzZAQHcawF/c7WLyJK7jLn9mxMJJlMTGXWmAXnK+PvH
  14.     tIMdbj2ef14VNnvSzGG2UGoTtjrcWvPi
  15.     =Z6h/
  16.  
  17. In article 6di@engnews1.Eng.Sun.COM, axl@zedat.fu-berlin.de (Axel Thimm)
  18. writes:
  19.  
  20. >Hello,
  21. >
  22. >I have had a look in the April draft, but I think that there is a small
  23. >ambiguity about eof() methods in streams.
  24. >Is the eof-flag raised, when the end of the stream is reached, or when
  25. >an attempt to move past this end is made?
  26.  
  27. It is deliberately not specified in detail, the same situation as with
  28. C stdio, and for the same reasons.
  29.  
  30. If the eof flag has been set, it means that the end of the file has been
  31. seen and that no more characters are available. It doesn't necessarily
  32. mean that you have attempted to read beyond the end yet. If the flag is
  33. not set, it doesn't mean that more characters are available.
  34.  
  35. The reason for the looseness in the definition is to allow for different
  36. kinds of input devices. From a pipe or keyboard, you don't know whether
  37. eof has been reached until you get a positive indication of eof. If no
  38. more characters are currently available, you don't know whether you are
  39. at eof until the next input item shows up (a character or an EOF). A
  40. test like
  41.     if( cin.eof() ) ...
  42. could wait indefinitely under such circumstances.
  43.  
  44. Standard Pascal, by contrast, requires predictive I/O. The file variable
  45. always contains the next available data or EOF. That is a nice model of
  46. I/O, but causes a problem for devices like keyboards and pipes: the
  47. program waits during file opening until input is available. (The program
  48. hangs during intialization until the user types something at the keyboard.)
  49. Consequently, most Pascal implementations don't follow the standard for
  50. console input, but use "lazy I/O" instead.
  51.  
  52. ---
  53. Steve Clamage, stephen.clamage@eng.sun.com
  54. ---
  55. [ To submit articles: try just posting with your news-reader.
  56.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  57.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  58.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  59.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  60. ]
  61.